package com.cykj.controller;

import com.cykj.bean.MessageBean;
import com.cykj.bean.MyGameRoom;
import com.cykj.bean.Tblgame;
import com.cykj.service.GameHallService;
import com.cykj.service.GameService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 类名称：$CLASSNAME$
 * <p>
 * 描述：游戏大厅控制器
 * 创建人: 小苏
 * 创建时间: 2023/02/01 17:06:50
 */
@RestController
@RequestMapping(value = "/gamehall" , method = {RequestMethod.POST,RequestMethod.GET})
@Api(tags = "游戏大厅后台")
public class GameHallController {
    @Autowired
    private GameService gameService;
    @Autowired
    private GameHallService gameHallService;

    /**
     * findgametype
     *
     * @param pid pid
     * @return {@link MessageBean }
     * @author 小苏
     * @date 2023/02/01 17:07:14
     */
    @RequestMapping("/findgametype")
    @ApiOperation(value = "显示根据游戏类型分类的数据", notes = "显示根据游戏类型分类的数据" )
    @ApiImplicitParam(name = "pid" ,value = "游戏类型参数",dataType = "integer")
    public MessageBean findgametype(Integer pid){
        if (pid == null){
            pid = 0 ;
        }
        List<Tblgame> gameByType = gameHallService.findGameByType(pid);
        return MessageBean.success("",gameByType);
    }
    @ApiOperation(value = "创建默认的游戏房间", notes = "创建默认的游戏房间" )
    @ApiImplicitParam(name = "gameid" ,value = "游戏id",dataType = "integer")
    @RequestMapping("/createRommBySys")
    public MessageBean createRommBySys(Integer gameid){
        boolean flag = gameHallService.insGameRoomBySys(gameid);
        if(flag)
            return MessageBean.success("插入成功",flag);
        else return MessageBean.fail("插入失败");
    }

    /**
     * 发现房间列表
     *
     * @param gameid gameid
     * @return {@link MessageBean }
     * @author 小苏
     * @date 2023/02/02 19:04:12
     */
    @ApiOperation(value = "查询游戏房间", notes = "查询游戏房间" )
    @ApiImplicitParam(name = "gameid" ,value = "游戏id",dataType = "integer")
    @RequestMapping("/findRoomList")
    public MessageBean findRoomList(Integer gameid){
        List<MyGameRoom> roomListbyGameid = gameHallService.findRoomListbyGameid(gameid);
        if (roomListbyGameid.size() > 0){
            return MessageBean.success("",roomListbyGameid);
        }
        return MessageBean.success("",null);
    }

    /**
     * ins现在用户房间
     *
     * @param roomid roomid
     * @param userid 用户标识
     * @return {@link MessageBean }
     * @author 小苏
     * @date 2023/02/07 16:03:53
     */
    @ApiOperation(value = "加入房间", notes = "加入房间" )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roomid" ,value = "房间id",dataType = "integer"),
            @ApiImplicitParam(name = "userid" ,value = "用户id",dataType = "integer"),
    })
    @RequestMapping("/insNowUserToRoom")
    public MessageBean insNowUserToRoom(Integer roomid,Integer userid){
        int insNowUserToRoom = gameHallService.insNowUserToRoom(roomid, userid);
        return MessageBean.success("",insNowUserToRoom);
    }


}
//